#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
#define Module 998244353
int tmpInt;ll tmpll;string tmpStr;char tmpChar;
vector<int>tmpIntVector;

struct node{
  ll val;
  int index;
};

bool cmp1(node a, node b){
  return a.val < b.val;
}

bool cmp2(node a, node b){
  return a.index < b.index;
}

int main(){
  #ifndef ONLINE_JUDGE
    auto start_clock = clock();
    //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif

  int N;cin>>N; 
  ll a[N],t[N];
  XH(i,0,N){
    scanf("%lld%lld", &a[i], &t[i]);
  }
  int Q;cin>>Q;
  node x[Q];
  XH(i,0,Q){
    scanf("%lld", &x[i].val);
    x[i].index = i;
  }
  sort(x,x+Q,cmp1);
  

  XH(i,0,N){
    if(t[i] == 1){
      XH(j,0,Q) x[j].val += a[i];
    }else if(t[i] == 2){
      XH(j,0,Q) x[j].val = max(x[j].val,a[i]);
    }else{
      XH(j,0,Q) x[j].val = min(x[j].val,a[i]);
    }
  }
  sort(x,x+Q,cmp2);
  XH(i,0,Q)
    printf("%lld\n",x[i].val);
  
  #ifndef ONLINE_JUDGE
    auto end_clock = clock();
    //cout<<"runtime: "<<end_clock - start_clock<<"ms"<<endl;
  #endif
  return 0;
}
